#include "onbonsource.h"
#include <string>
#include "fpga_manage.h"
#include "messageDeal/message_deal.h"

onbonsource* onbonsource::p_onbon_source = NULL;

#define UNFIXED_OCH

//s5p210
void onbonsource::s5p210_setup(int fd, int index)
{
    Ouint8 savle;
    Ouint8 data;
    Ouint8 addr;
    //input 27(enable clk in) out 74.43535
    Ouint8 value[] = /*{  0x02,0x00,0x11,0x09,0x7c,0x08,0x6c,0x02,0x09,
                        0xc8,0xf0,0x06,0x6b,0x25,0x2f,0x33,0x02,0x00,
                        0xc6,0xe0,0x00,0x00,0x00,0x00,0x0e,0x24,0x1f,
                        0x55,0x3c,0x38,0x80,0x04,0x00,0x00,0xf4,0xf4,
                        0x90,0x9b,0x6b,0xf3,0xad,0xcf,0x00,0x00,0x00,
                        0x00,0x00,0x00,0xf3,0xff,0xff,0x00,0x00,0x00,
                        0x00,0x00,0xc3,0xc2,0x00,0x00,0x00,0x00,0x05,
                        0x00 };*/
                    //input 27.17M(enable clk in) out 74.43535
                    /*{
                        0x02,0x00,0x11,0x3e,0x47,0x74,0x6c,0x03,0x3d,
                        0x43,0xf5,0x0a,0x6c,0x25,0x4a,0x33,0x01,0x74,
                        0x96,0x73,0x00,0x00,0x00,0x00,0x0a,0x24,0x11,
                        0xc3,0x0c,0x38,0x80,0x04,0x00,0x00,0xf4,0xf4,
                        0x98,0x9e,0x62,0x53,0xae,0xe7,0x00,0x00,0x00,
                        0x00,0x00,0x00,0xf3,0xff,0xff,0x00,0x00,0x00,
                        0x00,0x00,0xc3,0xc2,0x00,0x00,0x00,0x00,0x05,
                        0x00
                    };*/
                   //input 25M(disable clk in)out 74.43535

                    /*{
                        0x00,0x00,0x11,0x3b,0x1e,0x64,0x6c,0x05,0x03,
                        0x48,0xf0,0x06,0x63,0x25,0x28,0x33,0x03,0x06,
                        0x20,0xad,0x00,0x00,0x00,0x00,0x16,0x24,0x1a,
                        0x33,0x3c,0x38,0x80,0x04,0x00,0x00,0xdc,0xdc,
                        0x90,0x7d,0x69,0xe1,0xa0,0xef,0x00,0x00,0x00,
                        0x00,0x00,0x00,0xf3,0xff,0xff,0x00,0x00,0x00,
                        0x00,0x00,0xc3,0xc2,0x00,0x00,0x00,0x00,0x05,
                        0x00
                    };*/

                    //input 27 out 74.25
                    /*{
                        0x02,0x00,0x11,0x09,0x7b,0x00,0xd4,0x02,0x09,
                        0x7b,0xf0,0x06,0x6b,0x16,0xdc,0x23,0x01,0x90,
                        0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x24,0x1b,
                        0x55,0x33,0x38,0x80,0x04,0x00,0x00,0x5c,0x5c,
                        0x90,0x9b,0x6b,0xf3,0xad,0xcf,0x00,0x00,0x00,
                        0x00,0x00,0x00,0xf3,0xff,0xff,0x00,0x00,0x00,
                        0x00,0x00,0xc3,0xc2,0x00,0x00,0x00,0x00,0x05,
                        0x00
                    };*/
                    //input 27 out 74.3
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0x7b ,0x08 ,0xec ,0x02 ,0x09 ,
                        0x7b ,0x80 ,0x0a ,0x6b ,0x16 ,0xdc ,0x23 ,0x01 ,0x90 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x0a ,0x24 ,0x1b ,
                        0x33 ,0x33 ,0x38 ,0x80 ,0x04 ,0x00 ,0x00 ,0x5c ,0x5c ,
                        0x90 ,0x9b ,0x6b ,0xf3 ,0xad ,0xcf ,0x00 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,0xff ,0x00 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,0x00 ,0x00,0x05,
                        0x00
                    };*/
                    //input 27 out74.4
                   /* {
                        0x02 ,0x00 ,0x11 ,0x09 ,0x7c ,0x08 ,0xec ,0x02 ,0x09 ,0xc8 ,
                        0xe0 ,0x0a ,0x6b ,0x25 ,0x2f ,0x23 ,0x01 ,0x90 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0a ,0x24 ,0x1b ,0x23 ,0x30 ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input 27 out74.44()
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0x7c ,0x08 ,0x6c ,0x02 ,0x09 ,0xc8 ,
                        0xe0 ,0x0a ,0x6b ,0x25 ,0x2f ,0x23 ,0x01 ,0x90 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0a ,0x24 ,0x1b ,0xc3 ,0x3c ,0x30 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input 27 out74.45(ok out)
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0xf8 ,0x00 ,0xec ,0x03 ,0x09 ,0xc8 ,
                        0xf0 ,0x06 ,0x6b ,0x25 ,0x2f ,0x33 ,0x01 ,0x90 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0a ,0x24 ,0x1b ,0x33 ,0x30 ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input 27 out74.46(ok out)
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0xf8 ,0x00 ,0xec ,0x03 ,0x09 ,0xc8 ,
                        0xf0 ,0x06 ,0x6b ,0x25 ,0x2f ,0x33 ,0x01 ,0x90 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0a ,0x24 ,0x1b ,0x39 ,0x30 ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input 27 out74.47(ok out)
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0x7c ,0x08 ,0x6c ,0x02 ,0x09 ,0xc8 ,
                        0xf0 ,0x06 ,0x6b ,0x25 ,0x2f ,0x33 ,0x03 ,0x9e ,0xbc ,0xdf ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x1c ,0x24 ,0x1c ,0x99 ,0x3c ,0x3
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/

                    //input 27 out74.48(ok out)
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0x94 ,0x00 ,0x6c ,0x05 ,0x09 ,0xc8 ,
                        0xf0 ,0x06 ,0x6b ,0x25 ,0x2f ,0x33 ,0x02 ,0x32 ,0xbc ,0xdf ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x10 ,0x24 ,0x11 ,0x99 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input 27 out74.49(ok out)
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0x94 ,0x00 ,0x6c ,0x05 ,0x09 ,0xc8 ,
                        0xf0 ,0x06 ,0x6b ,0x25 ,0x2f ,0x33 ,0x02 ,0x0c ,0x30 ,0x5b ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0e ,0x24 ,0x13 ,0x33 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input 27 out74.50(ok out)
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0x7c ,0x08 ,0xec ,0x02 ,0x09 ,0x7c ,
                        0x80 ,0x0a ,0x6b ,0x17 ,0x0c ,0x23 ,0x01 ,0x90 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0a ,0x24 ,0x1b ,0x55 ,0x33 ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0x5c ,0x5c ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    #if 1//defined(UNFIXED_OCH)
                    //input xtal25 out148.5(OK for now  20211110)
                    {
                      #if 1//defined(SUPPORT_OCH_8K)
                        //BW_1OCH_162

        #if 0

                        0x00,0x00,0x11,0x19,0x44,0x11,0xec,0x08,0x03,0x48,
                        0xf0,0x06,0x63,0x25,0x28,0x13,0x00,0x30,0x00,0x00,
                        0x00,0x00,0x00,0x00,0x02,0x24,0x03,0x42,0x30,0x38,
                        0x80,0x04,0x00,0x00,0xdc,0xdc,0x90,0x7d,0x69,0xe1,
                        0xa0,0xef,0x00,0x00,0x00,0x00,0x00,0x00,0xf3,0xff,
                        0xff,0x00,0x00,0x00,0x00,0x00,0xc3,0xc2,0x00,0x00,
                        0x00,0x00,0x05,0x00
        #endif
                        //for 162M

                        //lvds 2
                        #if 0//(BW_1OCH_TYPE==BW_1OCH_162 || BW_1OCH_TYPE == BX_1OCH_162_2DIV_18H)
        #if 0
            // 1 2 4 ok
                        0x00,0x00,0x11,0x05,0x60,0x08,0xec,0x04,0x19,0x44,
                        0xf1,0x06,0x63,0x14,0x0f,0x43,0x00,0x30,0x00,0x00,
                        0x00,0x00,0x00,0x00,0x02,0x24,0x03,0x1e,0x33,0x38,
                        0x80,0x04,0x00,0x00,0xdc,0x5c,0x98,0x7d,0x69,0xe1,
                        0xa0,0xef,0x00,0x00,0x00,0x00,0x00,0x00,0xf3,0xff,
                        0xff,0x00,0x00,0x00,0x00,0x00,0xc3,0xc2,0x00,0x00,
                        0x00,0x00,0x05,0x00
        #endif

                        #ifdef VBY_OUT_3BYTEMODE_RGB24
                        /*121.5*/
                        0x00, 0x00, 0x11, 0x32, 0xd9, 0x42, 0xec, 0x01, 0x19, 0xe6,
                        0xf1, 0x06, 0x63, 0x1e, 0x16, 0x13, 0x00, 0x30, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x02, 0x24, 0x03, 0x88, 0x33, 0x38,
                        0x80, 0x04, 0x00, 0x00, 0x5c, 0x5c, 0x90, 0x7d, 0x69, 0xe1,
                        0xa0, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0xff,
                        0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc2, 0x00, 0x00,
                        0x00, 0x00, 0x05, 0x00
                        #else

                        //vlds 2 ,1M 1M  162M,411MA for 3 &5

                        0x00,0x00,0x11,0x05,0x60,0x08,0xec,0x0f,0x19,0x44,
                        0xf1,0x06,0x63,0x14,0x0f,0x43,0x00,0x30,0x00,0x00,
                        0x00,0x00,0x00,0x00,0x02,0x24,0x03,0x4e,0x33,0x38,
                        0x80,0x04,0x00,0x00,0xd4,0x54,0x98,0x7d,0x69,0xe1,
                        0xa0,0xef,0x00,0x00,0x00,0x00,0x00,0x00,0xf3,0xff,
                        0xff,0x00,0x00,0x00,0x00,0x00,0xc3,0xc2,0x00,0x00,
                        0x00,0x00,0x05,0x00
                        #endif


        #if 0
                        //vlds 2 ,1M 12M  162M,311MA for 3
                        0x00,0x00,0x11,0x19,0x44,0x11,0xec,0x04,0x19,0x80,
                        0xf1,0x06,0x63,0x17,0xc6,0xd3,0x00,0x30,0x00,0x00,
                        0x00,0x00,0x00,0x00,0x02,0x24,0x03,0x4e,0x33,0x38,
                        0x80,0x04,0x00,0x00,0x50,0xd0,0x98,0x7d,0x69,0xe1,
                        0xa0,0xef,0x00,0x00,0x00,0x00,0x00,0x00,0xf3,0xff,
                        0xff,0x00,0x00,0x00,0x00,0x00,0xc3,0xc2,0x00,0x00,
                        0x00,0x00,0x05,0x00

        #endif

                        #else
                        #ifdef VBY_OUT_3BYTEMODE_RGB24
                        /*121.5*/
                        0x00, 0x00, 0x11, 0x32, 0xd9, 0x42, 0xec, 0x01, 0x19, 0xe6,
                        0xf1, 0x06, 0x63, 0x1e, 0x16, 0x13, 0x00, 0x30, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x02, 0x24, 0x03, 0x88, 0x33, 0x38,
                        0x80, 0x04, 0x00, 0x00, 0x5c, 0x5c, 0x90, 0x7d, 0x69, 0xe1,
                        0xa0, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0xff,
                        0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc2, 0x00, 0x00,
                        0x00, 0x00, 0x05, 0x00
                        #else
                        /*BW_1OCH_148p5*/
                        0x00 ,0x00 ,0x11 ,0x32 ,0x7b ,0x53 ,0xec ,0x01 ,0x19 ,0x52 ,
                        0xf2 ,0x06 ,0x63 ,0x24 ,0xc7 ,0x13 ,0x00 ,0x30 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x24 ,0x03 ,0x11 ,0x33 ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0x74 ,0x74 ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                        #endif /*VBY_OUT_3BYTEMODE_RGB24*/
                        #endif


                        #if 0
                        //159.5M just for test
                        0x00,0x00,0x11,0x19,0x3f,0x11,0xec,0x04,0x19,0x3f,
                        0xf1,0x06,0x63,0x13,0xbf,0x43,0x00,0x30,0x00,0x00,
                        0x00,0x00,0x00,0x00,0x02,0x24,0x03,0x11,0x33,0x38,
                        0x80,0x04,0x00,0x00,0x5c,0x5c,0x90,0x7d,0x69,0xe1,
                        0xa0,0xef,0x00,0x00,0x00,0x00,0x00,0x00,0xf3,0xff,
                        0xff,0x00,0x00,0x00,0x00,0x00,0xc3,0xc2,0x00,0x00,
                        0x00,0x00,0x05,0x00
                        #endif
                      #else
                        /*BW_1OCH_148p5*/
                        0x00 ,0x00 ,0x11 ,0x32 ,0x7b ,0x53 ,0xec ,0x01 ,0x19 ,0x52 ,
                        0xf2 ,0x06 ,0x63 ,0x24 ,0xc7 ,0x13 ,0x00 ,0x30 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x24 ,0x03 ,0x11 ,0x33 ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0x74 ,0x74 ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                      #endif
                    };
                    #endif
                    #if 0//!defined(UNFIXED_OCH)
                    //input xtal25 out74.25(OK for now  20211210)
                    {
                        0x00 ,0x00 ,0x11 ,0x14 ,0x29 ,0x11 ,0xec ,0x02 ,0x14 ,0x29 ,
                        0xf1 ,0x06 ,0x63 ,0x16 ,0xfc ,0x23 ,0x00 ,0x30 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x02 ,0x24 ,0x03 ,0x55 ,0x33 ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0x5c ,0x5c ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };
                    #endif
                    //input xtal25 out148.55 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x38 ,0x33 ,0x85 ,0x6c ,0x08 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x02 ,0xe6 ,0xc0 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x16 ,0x24 ,0x19 ,0x22 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input xtal25 out148.45 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x2b ,0xfe ,0x42 ,0x6c ,0x01 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x02 ,0xe6 ,0x40 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x16 ,0x24 ,0x19 ,0x22 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input xtal25 out148.455 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x37 ,0x61 ,0xa6 ,0x6c ,0x02 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x01 ,0xab ,0x8c ,0xe7 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0c ,0x24 ,0x18 ,0x11 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input xtal25 out148.46 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x1b ,0xe1 ,0x21 ,0x6c ,0x01 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x01 ,0x4c ,0x8c ,0xe7 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x08 ,0x24 ,0x0e ,0x88 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input xtal25 out148.48 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x25 ,0x6f ,0x53 ,0x6c ,0x08 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x02 ,0x16 ,0x87 ,0x2b ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0e ,0x24 ,0x1e ,0x11 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input xtal25 out148.495 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x3f ,0x4f ,0xc7 ,0x6c ,0x02 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x02 ,0xb1 ,0x04 ,0x4d ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x14 ,0x24 ,0x1d ,0x88 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input xtal25 out148.499 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x3d ,0x3f ,0x64 ,0x6c ,0x01 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x02 ,0x04 ,0xc6 ,0xca ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0e ,0x24 ,0x1d ,0x11 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input xtal25 out148.4999 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x3d ,0x3f ,0x64 ,0x6c ,0x01 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x01 ,0x0b ,0x4c ,0xc1 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x06 ,0x24 ,0x0f ,0x11 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input xtal25 out148.5005 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x32 ,0x7b ,0x53 ,0x6c ,0x01 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x13 ,0x02 ,0x28 ,0x6b ,0xff ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x10 ,0x24 ,0x1f ,0x11 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input xtal25 out148.50001 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x32 ,0x7b ,0x53 ,0x6c ,0x01 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x02 ,0x99 ,0x47 ,0xb1 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x14 ,0x24 ,0x1c ,0x88 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/

                    //input xtal25 out148.500001 error(shardown error)
                    /*{
                        0x00 ,0x00 ,0x11 ,0x32 ,0x7b ,0x53 ,0x6c ,0x01 ,0x03 ,0x48 ,
                        0xf0 ,0x06 ,0x63 ,0x25 ,0x28 ,0x33 ,0x02 ,0x81 ,0x85 ,0x1f ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x12 ,0x24 ,0x1b ,0x88 ,0x3c ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x7d ,0x69 ,0xe1 ,
                        0xa0 ,0xef ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input 27 out148.5(ok to light)
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0x94 ,0x00 ,0xe4 ,0x01 ,0x09 ,0xc6 ,
                        0xf0 ,0x06 ,0x6b ,0x24 ,0xce ,0x13 ,0x01 ,0x90 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0a ,0x24 ,0x1b ,0x11 ,0x33 ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0x5c ,0x5c ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
                    //input 27 out148.500001 error(shardown error)
                    /*{
                        0x02 ,0x00 ,0x11 ,0x09 ,0x94 ,0x00 ,0xec ,0x01 ,0x09 ,0xc8 ,
                        0xf0 ,0x06 ,0x6b ,0x25 ,0x2f ,0x33 ,0x01 ,0x90 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x00 ,0x00 ,0x0a ,0x24 ,0x1b ,0x11 ,0x30 ,0x38 ,
                        0x80 ,0x04 ,0x00 ,0x00 ,0xdc ,0xdc ,0x90 ,0x9b ,0x6b ,0xf3 ,
                        0xad ,0xcf ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xf3 ,0xff ,
                        0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xc3 ,0xc2 ,0x00 ,0x00 ,
                        0x00 ,0x00 ,0x05 ,0x00
                    };*/
    switch (init_s5p210_state[index]) {
    case init_s5p210_start:
         s5p210_ic_valid[index] = 0x00;
        init_s5p210_state[index] = init_s5p210_step1;
#if 1
         savle = 0xD0;
         if(index == 0){
             BX_printf("\n-------------- ready to init fpga1 s5p210--------------  \n") ;
         }else{
             BX_printf("\n-------------- ready to init fpga2(near power) s5p210--------------  \n") ;

         }

         for(addr=0x00;addr<0x3F;addr++){
             if(p_drv_i2c_0->i2c_write(fd,savle,addr,&value[addr],1)==0){
                 init_s5p210_state[index] = init_s5p210_start;
                 break;
             }
         }

#endif

        break;
    case init_s5p210_step1:
        //try
        data = 0x00;
        savle = 0xD0;
        addr = 0x01;
        init_s5p210_flag[index] = TRUE;

        if(index == 0){
           // *(unsigned short *)(fpga_manage::p_fpga_manage->to_fpga1_reset) = GPIO17_CONTENT_H ;
        }
        init_s5p210_state[index] = init_s5p210_end;
        BX_printf("\n-------------- over to init fpga2(near power) s5p210--------------  \n") ;
        break;
    case init_s5p210_end:
        break;
    default:break;

    }
}






onbonsource::onbonsource()
{
    BX_printf("====onbonsource::onbonsource()=====") ;

    p_drv_i2c_0 = new Drv_I2C0;

    m_pidChecksource = 0;
    set_ext_change = 0;
//    set_custom_edid = 0;

    init_5338_state[0] = init_5338_start;
    init_5338_state[1] = init_5338_start;
    init_5338_flag[0] = false;


    init_s5p210_state[0] = init_s5p210_start;
    init_s5p210_state[1] = init_s5p210_start;
    init_s5p210_flag[0] = false;
    init_s5p210_flag[1] = false;
    set_custom_volume = 1;
    set_ext_change_step = 0;
    source_init_s1 = 0;
    cdce913_ic_valid = 0;
    init_cdce913_state = init_cdce913_start;

    onbonsource_init_step = onbonsource_init_step_over;

    init_66121_state = init_66121_start;

     source_status = 0;

}


onbonsource::~onbonsource()
{
    if(p_onbon_source != NULL){
        delete p_onbon_source;//
        p_onbon_source = NULL;
    }

    if(p_drv_i2c_0 != NULL){
        delete p_drv_i2c_0;
        p_drv_i2c_0 = NULL;


    }

}


onbonsource* onbonsource::pInstance()
{
    if(p_onbon_source == NULL){
        p_onbon_source = new onbonsource();
        p_onbon_source->initialize();
    }

    return p_onbon_source;
}

Oint8 onbonsource::initialize()
{

    m_drv_i2c0_fd = p_drv_i2c_0->initialize();







#if 1
    //创建管理线程
    if(0 != pthread_create(&m_pidChecksource, NULL, checksourceThread, this))
    {
        BX_printf("create manage thread failed\n");
        return -1;
    }
#endif

    return 0;
}


//命令管理线程，用于处理命令
void * onbonsource::checksourceThread(void * p_check_source)
{
    int i;
    Ouint8 pid_ctrl,FLAG,edid_source_start;
    Ouint16 addr;
    Ouint8 page = 8 ;//page=8 may for 24c02
    short volume_image/*,switch_mode*/;
    int volume_image_addr;

    Ouint16 m,j;
    Ouint8 buffer[256] ;
    Ouint8 sum ;
    char *str ;




    if(!p_check_source)
    {
        return 0;
    }
    //第一次链接上后1秒后发心跳
    //Ouint32 number = 1000*29;

    while(1)
    {


         if(p_onbon_source->source_init_s1 == 0){


            for(i=0;i<1;i++){

                if(p_onbon_source->init_s5p210_flag[i] == false){
                    // usleep(100);
                    sleep(1);
                    p_onbon_source->s5p210_setup(p_onbon_source->m_drv_i2c0_fd,i);
                }
            }
        }
    }
}






